/**
 * @param {number} m
 * @param {number} n
 * @param {number[][]} indices
 * @return {number}
 */
export var oddCells = function (m, n, indices) {
  const grid = new Array(m).fill(0).map(() => new Array(n).fill(0))
  let ans = 0
  for (const [r, c] of indices) {
    setToGrid(grid, r, c)
  }
  for (let i = 0; i < grid.length; i++) {
    for (let j = 0; j < grid[0].length; j++) {
      if (grid[i][j] % 2 === 1) ans++
    }
  }
  return ans
}

function setToGrid(grid, r, c) {
  for (let i = 0; i < grid.length; i++) {
    grid[i][c]++
  }
  for (let i = 0; i < grid[0].length; i++) {
    grid[r][i]++
  }
}

export var oddCells2 = function (m, n, indices) {
  const rows = new Array(m).fill(0)
  const cols = new Array(n).fill(0)
  for (const index of indices) {
    rows[index[0]]++
    cols[index[1]]++
  }
  let res = 0
  for (let i = 0; i < m; i++) {
    for (let j = 0; j < n; j++) {
      if (((rows[i] + cols[j]) & 1) !== 0) {
        res++
      }
    }
  }
  return res
}
